#-*-coding:utf-8-*-
#author:fanerlei
# 替换空格
# 左旋字符串

def replaceSpace(tmpStr):
	return tmpStr.replace(" ","%20")

def replaceSpaceNew(tmpStr):
	tmpList = []
	for char in tmpStr:
		if char == " ":
			tmpList.append("%20")
		else:
			tmpList.append(char)
	return "".join(tmpList)


def reverseLeftWords(s, n):
	"""
	:type s: str
	:type n: int
	:rtype: str
	"""
	if not s:
		return s
	strCount = len(s)
	n = n if n < strCount else strCount
	oriStr = s[n:strCount]
	newStr = s[0:n]
	return oriStr + newStr

if __name__ == "__main__":
	tmpStr = "We are happy."
	print replaceSpace(tmpStr)
	print replaceSpaceNew(tmpStr)
	print reverseLeftWords("abcdefg",2)